home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / future86.arc / DRIVER.FIF < prev    next >
Encoding:
Text File  |  1987-04-20  |  30.7 KB  |  1,099 lines

  1. TITLE   'DRIVER...Console out file driver'
  2. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  3. \\\This demonstration source code is copyrighted and is for the   \\\
  4. \\\express use of FUTURE86 users persuant to the terms of the     \\\
  5. \\\FUTURE86 license.                                              \\\
  6. \\\                                                               \\\
  7. \\\Copyright (C)1987 Development Associates                       \\\
  8. \\\All rights reserved                                            \\\
  9. \\\                                                               \\\
  10. \\\This source code may be evaluated by potential FUTURE86        \\\
  11. \\\users to determine product suitability.                        \\\
  12. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  13. \\\Some resources in this file are not utilized by                \\\
  14. \\\the demonstration program.                                     \\\
  15. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  16. \\\ RFD Revised 4-02-87 --general file cleanup                    \\\
  17. \\\             4-17-87 --added recoding examples                 \\\
  18. \\\             4-18-87 --added cpu timing independence           \\\
  19. \\\             4-19-87 --added scale music                       \\\
  20. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  21. PAGE
  22.  
  23. \\\Define system constants, etc..
  24.  
  25. ESCAPE          EQU     27             \ESCAPE key
  26.  
  27. SCREENSIZE      DW      184FH       \18=hex rows, 4F=columns
  28.  
  29. CRTATR          DB      07          \VIDEO Attribute
  30.  
  31. PAGE#           EQU     0:462H      \DOS page addr
  32.  
  33. LRCORN          EQU     217            \CODE for LR char
  34.  
  35. ULCORN          EQU     218            \CODE for UL char
  36.  
  37. LLCORN          EQU     192            \CODE for LL char
  38.  
  39. URCORN          EQU     191            \CODE for UR char
  40.  
  41. \\\SCREEN ATTRIBUTE CONTROL\\\
  42.  
  43. : GET_ATR 
  44.         CRTATR B@ SWAP ;      \get ATR & put under mask
  45.  
  46. \NOTE: THESE MODES CAN BE MIXED
  47.  
  48. : VSET                          \logical OR
  49.         GET_ATR FOR 
  50.         CRTATR B! ;
  51.  
  52. : VCLR                          \logical AND
  53.         GET_ATR FAND 
  54.         CRTATR B! ;
  55.  
  56. PAGE
  57.  
  58. \THE NEXT WORDS SET UP THE VIDEO ATRIBUTES BUT DO NOT CAUSE
  59. \ANY ACTION UNTIL EITHER FCO OR XCO AND THEIR DERIVATIVES
  60. \ARE USED(these words are defined later in this file)
  61.  
  62. : NORM                          \normal video attribute
  63.         7 VCLR 
  64.         7 VSET ;
  65.  
  66. : INTENS                        \intensified chars
  67.         01000B VSET ;
  68.  
  69. : -INTENS                       \cancel intensity
  70.         11110111B VCLR ;
  71.  
  72. : BLINK                         \char blinking
  73.         10000000B VSET ;
  74.  
  75. : -BLINK                        \cancel char blink
  76.         1111111B VCLR ;
  77.  
  78. : REVERSE                       \reverse video
  79.         01110000B VSET
  80.         11111000B VCLR ;
  81.  
  82. : -REVERSE                      \cancel reverse video
  83.         111B VSET
  84.         10001111B VCLR ;
  85.  
  86.  
  87. : BLACK                         \dark screen--no chars
  88.         10001000B VCLR ;
  89.  
  90. : WHITE                         \bright screen--no chars
  91.         01110111B VSET ;
  92.  
  93. PAGE
  94.  
  95. \\\DEFINE INT 10H STRUCTURE
  96.  
  97. : INT_10H
  98.         10H SET_INT_NO
  99.         !AH
  100.         SYSTEM_CALL
  101.         RESTORE_INT_NO ;
  102.  
  103. \\\SET VIDEO MODE
  104.  
  105. \NOTE THAT PROCEDURE NAMES CAN BE SELECTED TO DOCUMENT TO ANY
  106. \DESIRED LEVEL--THERE REALLY CAN NOT BE ANY DOUBT ABOUT WHAT THE
  107. \NEXT FEW WORDS DO
  108.  
  109. \EQU FOR VIDEO MODE SELECTION
  110. 40X25_BW        EQU     0
  111. 20X25_COLOR     EQU     1
  112. 80X25_BW        EQU     2
  113. 320X200_COLOR   EQU     3
  114. 320X200_BW      EQU     4
  115. 320X200_GRAPH   EQU     5
  116. 640X200_GRAPH   EQU     6
  117. 80X25_MONO      EQU     7           \mono card only
  118.  
  119. : SET_VIDEO_MODE        \mode ---
  120.         !AL             \store mode
  121.         0               \operation type
  122.         INT_10H  ;
  123.  
  124. PAGE
  125.  
  126. \\\SET ACTIVE PAGE#\\\
  127.  
  128. : ?PAGE#   
  129.         PAGE# B@ ;      \Get active page no.
  130.  
  131. : SET_PAGE#             \PAGE# ---
  132.                         \page no. = 0--3 for CGA
  133.         !AL
  134.         5 INT_10H ;
  135.  
  136. \\\FORCE CURSOR POSITION
  137.  
  138. : PUT_CURS              \ row colm ---
  139.         !DL             \colm
  140.         !DH             \row
  141.         ?PAGE#  !BH
  142.         2 INT_10H ;
  143.  
  144. \\\FIND CURSOR POSITION\\\
  145.  
  146. : GET_CURS      \ --- Attrib row colm
  147.         ?PAGE# !BH
  148.         3 INT_10H
  149.         @CX             \get atr
  150.         @DH             \get row
  151.         @DL  ;          \get colm
  152.  
  153. : HOME          \move cursor to upper left of screen
  154.         0 !DX
  155.         ?PAGE# !BH
  156.         2
  157.         INT_10H ;
  158.  
  159. \\\CLEAR DESIRED SCREEN AMOUNT\\\
  160.  
  161. : CLR                           \srow scolm erow ecolm
  162.         0 !AL
  163.         !DL                     \ecolm 
  164.         !DH                     \erow
  165.         !CL                     \sclm
  166.         !CH                     \srow
  167.         CRTATR B@ !BH           \crtatr
  168.         6 INT_10H ;
  169.  
  170. PAGE
  171.  
  172. \\\READ SCREEN CHAR AT CURSOR\\\
  173.  
  174. : READ_CHAR/AT  \ --- atr char
  175.         ?PAGE# !BH              \page no.
  176.         8 INT_10H
  177.         @AH                     \atr
  178.         @AL ;                   \char
  179.  
  180. \\\WRITE SCREEN CHARS AT CURSOR\\\
  181.  
  182. : WRITE_CHAR/AT         \char size ---
  183.         ?PAGE# !BH      \page no.
  184.         !CX             \no. of chars to write
  185.         !AL             \char
  186.         CRTATR B@ !BL   \atr
  187.         9 INT_10H ;
  188.  
  189. : WRITE_ATR             \ ---
  190.         READ_CHAR/AT    \ get char & atr at curs pos
  191.         DROP2ND  
  192.         1
  193.         WRITE_CHAR/AT ;  \rewrite char w/new atr
  194.  
  195. : CLR_SCREEN    \CLEAR ENTIRE SCREEN
  196.         0  0   
  197.         24 79 CLR ;
  198.  
  199. : CLS                           \same as IBM CLS
  200.         HOME CLR_SCREEN ;         
  201.  
  202. : BEL           \ring computer bell
  203.         7 CO ;                    
  204.  
  205. \\\SCROLL CONTROL
  206.  
  207. : SCROLL_UP_LINES          \n1(lines to scroll up) ---
  208.           !AL              \no. lines to scroll
  209.         0 !CX              \start scroll at UL corner
  210.         SCREENSIZE @ !DX   \end row,column of scroll
  211.         CRTATR B@ !BH      \atr used on blank line
  212.         6 INT_10H ;
  213.  
  214. : SCROLL_UP_ONE_LINE
  215.         1 SCROLL_UP_LINES ;
  216.  
  217. PAGE
  218.  
  219. \\\The next word, FCO, is a console out procedure and is written mostly
  220. \in assembly language for maximum speed. This has the same function 
  221. \as the kernel word CO but is faster.  An even faster and less
  222. \portable method would be a direct hardware access but that should
  223. \not be used except in the most time critical applications.
  224. \A word that follows, XCO, is a mix of high level and assembly. 
  225. \FCO runs much faster than XCO which shows the speed advantage 
  226. \that low level code can yield. However, XCO is much more readable 
  227. \and was obviously easier to write. In fact, FCO was written after 
  228. \XCO was developed and was used as the basis for coding FCO. this is
  229. \a good example of a valid development technique--first prototyping in 
  230. \high level and then--if the application requires-rewriting in assembler.
  231.  
  232. \Note the use of local labels signified by the "_" character 
  233. \in front of the label.
  234.  
  235. : FCO
  236.          PUSH ES                         \preset es:=0
  237.          MOV AX,0                        \= DOS low memory
  238.          MOV ES,AX
  239.          MOV     AH,3                    \get cursor pos.
  240.          MOV     BH,BYTE ES:PAGE#        \get current disp. page
  241.          PUSH BP 
  242.          INT 10H 
  243.          POP BP  
  244. \
  245.          MOV     AL,[BP]                 \load the character
  246.          CMP     AL,0DH                  \CR?
  247.          JNE     _FCO_BS                 \branch if not
  248.          MOV     DL,0                    \clear column reg.
  249.          JMP     _FCO2                   \set cursor and return
  250. _FCO_BS:
  251.          CMP     AL,08                   \BS?
  252.          JNE     _FCOLFX                 \branch if not
  253.          CMP     DL,0                    \far left colmn?
  254.          JE      _FCO2                   \branch if so
  255.          DEC     DL                      \else decrement cursor
  256.          JMP     _FCO2                   \set cursor & return
  257. _FCOLFX:                                
  258.          CMP     AL,0AH                  \LF?
  259.          JE      _FCO_LF                 \branch if so
  260. _?BEL:   CMP     AL,7
  261.          JNE     _FCO_CHR
  262. _BEL:  
  263.          BEL                            \speed not important; so hi level
  264.          JMP _XDN                       \now drop stack and exit
  265. \
  266.  
  267. PAGE
  268.  
  269. _FCO_CHR:         
  270.          PUSH    DX                      \save current cursor
  271.          MOV     AH,9                    \write current atr & chr
  272.          MOV     BL,BYTE CS:CRTATR       \get char attribute
  273.          MOV     BH,BYTE ES:PAGE#        \get page no.
  274.          MOV     CX,1                    \char count
  275.          PUSH    BP 
  276.          INT     10H 
  277.          POP     BP  
  278.          POP     DX                      \get current cursor
  279.          INC     DL                      \advance colmn
  280.          CMP     DL,80                   \colmn limit?
  281.          JNZ     _FCO1                   \branch if not
  282.          MOV     DL,0                    \set far left position
  283. _FCO_LF:
  284.          INC     DH                      \advance row
  285. _FCO1:   CMP     DH,24                   \row limit?
  286.          JLE     _FCO2                   \branch if not
  287.          MOV     DH,24                   \set bottom position
  288.          PUSH    DX                      \save cursor position
  289.          MOV     AX,601H                 \scroll up one line
  290.          MOV     CX,0                    \left upper corner
  291.          MOV     DX,CS:SCREENSIZE        \right lower corner
  292.          MOV     BH,CS:CRTATR            \attribute
  293.          PUSH    BP 
  294.          INT     10H 
  295.          POP     BP  
  296.          POP     DX                      \get cursor position
  297. _FCO2:   
  298.          MOV     AH,2                    \set new cursor position 
  299.          MOV     BH,BYTE ES:PAGE#        \active display page
  300.          PUSH    BP 
  301.          INT     10H 
  302.          POP     BP  
  303. _XDN:    ADD     BP,4                    \clean stack
  304.          POP     ES           ;          \finally, the end of FCO
  305.                                         
  306. PAGE
  307.  
  308. \\\XCO IS A GOOD EXAMPLE OF MIXING ASSEMBLY AND HI-LEVEL IN A MODELESS
  309. \WAY THAT IS NATURAL WITH FUTURE86.
  310.  
  311. : XCO 
  312.         ?PAGE# !BH               \select page no.
  313.         3 INT_10H
  314.         @DH
  315.         24 < 
  316.       IF
  317.         JMP _OUTPUT              \branch if now row limit
  318.       ELSE
  319.             SCROLL_UP_ONE_LINE   \hi-level scroll..but just once/line
  320.                 23 0 PUT_CURS    \adjust cursor position
  321.      THEN
  322. _OUTPUT:                         \this is local label
  323.         WRITE_ATR                \put the character attribute
  324.               CO ;               \write the character
  325.  
  326. \STRING OUTPUT VERSION THAT USES FCO
  327.  
  328. : FPRINTS
  329.         BEGIN                 \string(addr,length)--- 
  330.           ?NULL 
  331.         -IF
  332.           CGET FCO
  333.         REPEAT ;
  334.  
  335. : BACK_UP               \backspace, nondestructive
  336.         08 FCO ;
  337.  
  338. : FCRLF 
  339.         10 FCO                  \line feed
  340.         13 FCO ;                \carriage return
  341.  
  342. \GENERATE MULTIPLE CRS
  343.  
  344. : CRS                   \ n ---
  345.         DO
  346.           FCRLF
  347.         LOOP ;
  348.  
  349. : DRAW          \ char # ---
  350.         DO 
  351.           DUP FCO 
  352.         LOOP DROP ;
  353.  
  354. : SEP                     \make a line of '=' marks
  355.         205 80 DRAW ;   
  356.  
  357. PAGE
  358.  
  359. \\\PRIMATIVE TEXT LINES\\\
  360.  
  361. : LF                 \linefeed
  362.         10 FCO ;
  363.  
  364. : H_BIT              \make a '-'
  365.         196 FCO ;
  366.  
  367. : V_BIT              \make a vertical mark
  368.         179 FCO ;
  369.  
  370. : HLINE              \horiz line from curs pos
  371.         1 MAX 
  372.        DO 
  373.         H_BIT
  374.        LOOP ;        
  375.  
  376. : VLINE              \vert line from curs pos
  377.         GET_CURS 
  378.         DSWAP DROP
  379.         1 MAX 
  380.         DO 
  381.           DDUP PUT_CURS
  382.             V_BIT 
  383.         1+2ND
  384.         LOOP 
  385.         DDROP ;
  386.  
  387. : LIMIT
  388.         2 MAX 2 - ;
  389.  
  390. : SETUP_BOX     \manipulate stack
  391.         DSWAP LIMIT 
  392.         SWAP  LIMIT
  393.         SWAP DSWAP DDUP
  394.         PUT_CURS  ;
  395.  
  396. PAGE
  397.  
  398. : TOP_LINE      \draw top horiz
  399.         ULCORN FCO 
  400.         4 PICK HLINE
  401.         URCORN FCO
  402.         BACK_UP
  403.         LF  ;
  404.  
  405. : RVERT_LINE    \draw right vert
  406.         3 PICK VLINE ;
  407.  
  408. : LVERT_LINE    \draw left vert
  409.         PUT_CURS LF
  410.         VLINE
  411.         BACK_UP 
  412.         LLCORN FCO ;
  413.  
  414. : BOT_LINE      \draw bot horiz
  415.         HLINE LRCORN FCO ;
  416.  
  417. : BOX           \horizlen vertlen row colm --- box
  418.         SETUP_BOX       \horizlen = 80 MAX
  419.         TOP_LINE        \vertlen  = 24 MAX
  420.         RVERT_LINE  
  421.         LVERT_LINE
  422.         BOT_LINE ;
  423.  
  424. PAGE
  425.  
  426. \\\SOUND\\\
  427.  
  428. TMR_MDE_REG     EQU     0B6H    \timer mode register
  429.  
  430. TM_MDE_PRT      EQU     43H     \timer mode port
  431.  
  432. SCALE           EQU     1221    \freq scale# for IBM PC
  433.  
  434. TMR2_PRT        EQU     42H     \timer 2 port
  435.  
  436. PRTB            EQU     61H     \timer port B
  437.  
  438. SPK_ON          EQU     03      \'on' command code
  439.  
  440. SPK_OFF         EQU      1      \'off' command code
  441.  
  442. SAVEIT          DW       0      \command save bucket
  443.  
  444. : SETUP                         \ --- ; init reg & port
  445.         TMR_MDE_REG 
  446.         TM_MDE_PRT  
  447.         FOUT ;
  448.  
  449. : FREQ                          \ freq ---
  450.         SCALE  
  451.         1000 D* 
  452.         SWAP D/ 
  453.         DUP TMR2_PRT 
  454.         FOUT 
  455.         8 SR 
  456.         TMR2_PRT FOUT ;
  457.  
  458. : SOUND_ON                      \ --- ;activate tone generator
  459.         PRTB FIN DUP 
  460.         SAVEIT ! 
  461.         SPK_ON 
  462.         FOR 
  463.         PRTB FOUT ;
  464.  
  465. PAGE
  466.  
  467. : OFF                           \turn tone off
  468.         SAVEIT @ 
  469.         PRTB FOUT ;
  470.  
  471. : TONE_CHANGE                   \ freq ---  ;to change tone pitch
  472.         SETUP FREQ ;
  473.  
  474. : TONE                          \freq, in cps ---
  475.         TONE_CHANGE 
  476.         SOUND_ON ;
  477.  
  478. \\\equates for musical notes, cps
  479. CNXT   EQU            528
  480. ANAT   EQU            440 
  481. BNAT   EQU            495 
  482. GNAT   EQU            396 
  483. FNAT   EQU            352 
  484. ENAT   EQU 330 
  485. DNAT   EQU 297 
  486. CNAT   EQU 264 
  487.  
  488.  
  489.  
  490. PAGE
  491.  
  492. \ This section displays the contents of a text file.
  493. \ By use of a separate script file each character 
  494. \ output can be controlled as to format and speed and
  495. \ screen placement. 
  496. \ Script file contains the following characters
  497. \ that change the output text mode as follows:
  498.  
  499. \ a ... normal output, next 3 bytes = #chars to output
  500. \ b ... inverse output, "
  501. \ c ... blink output,   "
  502. \ d ... intensity,      "
  503.  
  504. \ e ... Reset delay
  505. \ f ... set shortest delay
  506. \ g ... set longer delay
  507. \ h ... set longer delay
  508. \ i ... set longest delay 
  509.  
  510. \ j ... clear screen, put cursor at 0 0
  511.  
  512. \ k ... move cursor, next 2 bytes are x,y
  513. \ l ... send prompt message to screen and wait for input
  514. \ m ... output string(no format change), next 3 bytes=#chars
  515. \ n ... make a computer bell
  516. \ o ... execute programmed delay
  517. \ p ... draw a box, next 4 bytes are ysize,xsize,row,colm
  518. \ q ... switch to 1st display page
  519. \ r ... switch to 2nd display page
  520. \ s ... make programmed tone
  521. \ t ... turn tone off
  522. \ u ... make a click
  523. \ v ... clr desired part of screen, 
  524. \       next 4 bytes are srw,sclm,erw,eclm
  525. \ X ... programmed end of program...outputs message to crt.
  526. \ CR and other characters in the script 
  527. \    file are disregarded
  528.  
  529. PAGE
  530.  
  531. CTLC    EQU     3
  532.  
  533. EXIT_FLG        DSW
  534.  
  535. OUTPUT_COUNT    DSW
  536.  
  537. FILE_SIZE       EQU     25000
  538.  
  539. SCRIPT_BUF      DSB      4000      \script buffer reservation
  540.  
  541. FILE_BUF        DSB FILE_SIZE      \text file buffer reservation
  542.  
  543. : SET_EXIT  
  544.         EXIT_FLG 1! ;
  545.  
  546. \\\Programmed delay...insensitive to cpu clock speed
  547. \\\Please note: FUTURE86 makes this easier than in most
  548. \\\other languages..we do not need to save and then restore
  549. \\\all sorts of machine status to do this
  550.  
  551. DELAY_TIME      DW    0                 \variable for needed delay 
  552.  
  553. TIMER_INT       EQU   70H               \01CH * 4..user timer vector
  554.  
  555. TIMER_COUNT     DW    0                 \counter bucket
  556.  
  557. ORIG_VECTOR     DD     0                \save loc. for orig addr
  558.  
  559. : TIMER_DONE                            \reset bucket
  560.         TIMER_COUNT 0! ;
  561.  
  562. : SET_ORIG_VECTOR                       \restore user vector
  563.         ORIG_VECTOR D@        
  564.         TIMER_INT  D! ;       
  565.  
  566. \next is in assembler for low overhead during timer tick
  567. : INC_TIMER                             \this is new user code
  568. TIMER_VECTOR:                           \ref. addr label
  569.                 INC CS:TIMER_COUNT      \new entry point
  570.                 IRET                    \done
  571.                   ;
  572.  
  573. PAGE
  574.  
  575. : SET_NEW_VECTOR                        \install the user vector
  576.         TIMER_VECTOR  
  577.         TIMER_INT D! ;
  578.  
  579. : SAVE_ORIG_VECTOR                      \save so we know what to put back
  580.         TIMER_INT  D@ 
  581.         ORIG_VECTOR D! ;
  582.  
  583. : SET_DELAY             \ n1 ---  (each # is approx 55 ms)
  584.         DELAY_TIME ! 
  585.         0 ;
  586.  
  587. : ?TIMER_DONE           \stay here until we time out
  588.         BEGIN
  589.           TIMER_COUNT @ 
  590.           DELAY_TIME @ 
  591.           >  DUP
  592.           IF 
  593.             SET_ORIG_VECTOR
  594.             TIMER_DONE
  595.           THEN 
  596.         UNTIL  ;
  597.  
  598. : DELAY                         \programmable delay
  599.         DELAY_TIME @ 
  600.        IF 
  601.         SET_NEW_VECTOR          \turn on timer
  602.         ?TIMER_DONE             \wait till done and continue
  603.        THEN ;    
  604.  
  605. : INIT_TIMER                    \this saves orig vector and initializes
  606.         SAVE_ORIG_VECTOR
  607.         TIMER_COUNT 0!
  608.         DELAY_TIME 0! ;
  609.  
  610. \\\PLAY THE SCALE
  611.  
  612. : DURATION
  613.         3 SET_DELAY DROP DELAY ;
  614.  
  615. : NOTE
  616.         TONE DURATION OFF ;
  617.         
  618. : PLAY
  619.         8 DO NOTE LOOP ;
  620.  
  621. : SCALE_DOWN
  622.                 CNAT 
  623.                 DNAT 
  624.                 ENAT 
  625.                 FNAT 
  626.                 GNAT 
  627.                 ANAT 
  628.                 BNAT 
  629.                 CNXT ;
  630.  
  631. : SCALE_UP
  632.                 CNXT 
  633.                 BNAT 
  634.                 ANAT 
  635.                 GNAT 
  636.                 FNAT 
  637.                 ENAT 
  638.                 DNAT 
  639.                 CNAT ;
  640.  
  641. \if below is executed by itself..be sure to execute INIT_TIMER first
  642. : SCALE_UP/DOWN 
  643.         SCALE_DOWN   
  644.         SCALE_UP 
  645.         2 
  646.        DO
  647.         PLAY 
  648.        LOOP ;
  649.  
  650. \the commented out code is used if just software delay is used
  651. \: SET_DELAY 
  652. \        DELAY_TIME ! 0 ;
  653.  
  654.  
  655. \: DELAY                         \programmable delay
  656. \        DELAY_TIME @ 
  657. \       IF 
  658. \         DELAY_TIME @ 
  659. \          DO 
  660. \          LOOP 
  661. \       THEN ;    
  662.  
  663. PAGE
  664.  
  665. \\\Misc. text messages 
  666. : FPRINTS+CRS
  667.         FCRLF FPRINTS FCRLF ;
  668.  
  669. : ESC_MSG
  670.         "Esc key depressed..." ;
  671.  
  672. : OUTPUT_ESC_MSG
  673.         ESC_MSG FPRINTS+CRS ;
  674.  
  675. : ?USER_KEY             \test for user Esc key depress
  676.         CONSTS
  677.          IF
  678.            DCI ESCAPE =
  679.             IF
  680.                OUTPUT_ESC_MSG 
  681.                SET_EXIT
  682.             THEN
  683.          THEN  ;
  684.  
  685. \Output string to monitor with program. interchar delay
  686. : CPRINTS                            \sinfo ---
  687.         BEGIN                  
  688.           CGET 
  689.           DELAY FCO
  690.           ?NULL 
  691.         -IF
  692.         REPEAT ;
  693.  
  694. : RETMSG
  695.         FCRLF 4 SPACES 
  696.         " Press Esc key to abort or SPACE bar to continue..." 
  697.         INTENS REVERSE 
  698.         FPRINTS NORM  
  699.      BEGIN DCI 
  700.            DUP 32 = SWAP 
  701.            ESCAPE = DUP 
  702.            EXIT_FLG ! FOR
  703.      UNTIL 
  704.          EXIT_FLG @ 
  705.      IF  FCRLF
  706.          OUTPUT_ESC_MSG 
  707.      THEN ;
  708.  
  709. PAGE
  710.  
  711. : FATAL_ERROR_COND              \ ---
  712.         FCRLF DISPLAY_ERR_MSG 
  713.         FCRLF RETMSG REBOOT ;
  714.                                 
  715. : TEST_ERROR                    \cond ---
  716.         -IF 
  717.            FATAL_ERROR_COND
  718.         THEN ;
  719.  
  720. : ?OPEN_FILE                    \ ---
  721.         GET_ARG 
  722.         OPEN 
  723.         TEST_ERROR ;
  724.  
  725. : OPEN_FILES
  726.         ?OPEN_FILE SET#1               \open text file
  727.         ?OPEN_FILE SET#2 ;             \open script file
  728.  
  729. : CLOSE_FILES                   \ ---
  730.         #1 CLOSE DROP           \ignore error flags
  731.         #2 CLOSE DROP ;
  732.  
  733. : READ_TEXT_FILE                \ --- sinfo
  734.         FILE_BUF FILE_SIZE 
  735.         #1 READ TEST_ERROR ;
  736.  
  737. \ --- sinfo(txt) sinfo(script) 
  738. : READ_FILES
  739.          READ_TEXT_FILE
  740.          SCRIPT_BUF 4000 #2 READ
  741.          TEST_ERROR ;
  742.  
  743. PAGE
  744. \The next few words are examples of how much easier coding
  745. \in FUTURE86 can be. The commented out (with the '\' character)
  746. \definitions are coded in high level FUTURE86 and is quite efficient, 
  747. \but active definitions that follow with the same names are 
  748. \coded at even a higher level that really simplifies the 
  749. \code and its readability.
  750.  
  751. \: 3BYTE#                        \sinfo --- sinfo
  752. \        OVER                    \get starting address of no.
  753. \        3                       \string is 3 bytes long
  754. \        DECIMAL-BIN             \convert to bin. no.
  755. \        DROP                    \assume success, drop flag
  756. \        OUTPUT_COUNT !          \save converted value to variable
  757. \        SWAP                    \get original addr of string
  758. \        3 +                     \push it up by no. amount
  759. \        SWAP                    \put it back
  760. \        3 -   ;                 \adjust string length and finished
  761.  
  762. \get characters from string and convert to an n digit number
  763.  
  764. : NUMBER_GET            \sinfo n1 --- sinfo n2
  765.         SSPLIT 
  766.         DECIMAL-BIN 
  767.         -IF 
  768.            CRLF 
  769.            "Invalid number...Abort..."  \the fatal error msg
  770.            SPRINT
  771.            REBOOT       \its a fatal error...return to DOS
  772.         THEN ;
  773.  
  774. : 3BYTE#                \sinfo --- sinfo
  775.         3 NUMBER_GET 
  776.         OUTPUT_COUNT ! ;
  777.  
  778. PAGE
  779.  
  780. \: 2_CONV
  781. \        OVER 2 DECIMAL-BIN DROP ;       \subprocess for next words
  782. \
  783. \: TWO_ADJ                               \another subprocess
  784. \        SWAP 2+ SWAP 2 - ;
  785.  
  786. \: TWO_2CHR#                    \sinfo --- sinfo  row colm
  787. \        2_CONV
  788. \        >R                      \save in return stack
  789. \        TWO_ADJ                 \adjust string addr
  790. \        \1st byte finished
  791. \        2_CONV
  792. \        >R
  793. \        TWO_ADJ
  794. \        R> R>                   \get nos. back to stack
  795. \        SWAP   ;                \put them in correct order and done
  796. \
  797.  
  798. : 2CHR#                 \sinfo --- sinfo n1 
  799.         2 NUMBER_GET ; 
  800.  
  801. : TWO_2CHR#            \sinfo --- sinfo n1 n2
  802.         2CHR# >R 
  803.         2CHR# R> SWAP ;
  804.  
  805. PAGE
  806.  
  807. \: FOUR.NUMBERS                  \sinfo --- sinfo sr sc er ec
  808. \        2_CONV
  809. \        >R
  810. \        TWO_ADJ
  811. \        \1st byte
  812. \        2_CONV
  813. \        >R
  814. \        TWO_ADJ
  815. \        \2nd byte
  816. \        2_CONV
  817. \        >R
  818. \        TWO_ADJ
  819. \        \3rd byte
  820. \        2_CONV
  821. \        >R
  822. \        TWO_ADJ
  823. \        \4th byte
  824. \        R> R> R> R>             \get data back to stack
  825. \        SWAP                    \reorder values
  826. \        DSWAP
  827. \        SWAP ;
  828.  
  829. \define temp no. storage
  830. NUM1    DSW           
  831. NUM2    DSW
  832. NUM3    DSW
  833. NUM4    DSW
  834.  
  835. : FOUR.NUMBERS          \sinfo --- sinfo n1 n2 n3 n4
  836.         2CHR#  NUM1 !   \get 1st no
  837.         2CHR#  NUM2 !   \2nd no
  838.         2CHR#  NUM3 !   \3rd no
  839.         2CHR#  NUM4 !   \4th no
  840.                NUM1 @   \put result nos. on stack
  841.                NUM2 @ 
  842.                NUM3 @ 
  843.                NUM4 @ ;
  844.  
  845. : NO_TEXT_MSG
  846.         "Text exhausted"
  847.         FPRINTS+CRS ;
  848.  
  849. : PROGRAMMED_END                \for debug
  850.         "Programmed end of text.."
  851.         FPRINTS+CRS ;
  852.  
  853. PAGE
  854.  
  855. : NORMZ                              \ --- flg
  856.         NORM 3BYTE# 1 ;
  857.  
  858. : REVERSEZ                           \ --- flg
  859.         REVERSE 3BYTE# 1 ;
  860.  
  861. : BLINKZ                             \ --- flg
  862.         BLINK 3BYTE# 1 ;
  863.  
  864. : INTENSZ                            \ --- flg
  865.         INTENS 3BYTE# 1 ;
  866.  
  867. : SDELAY1                            \ --- flg
  868.         1 SET_DELAY ;
  869.  
  870. : SDELAY2                            \ --- flg
  871.         2 SET_DELAY ;
  872.  
  873. : SDELAY3                            \ --- flg
  874.         8 SET_DELAY ;
  875.  
  876. : SDELAY4                            \ --- flg
  877.         10 SET_DELAY ;
  878.  
  879. : RESET_DELAY                        \ --- flg
  880.         0  SET_DELAY ;
  881.  
  882. : CLSZ                               \ --- flg
  883.         CLS 0 ;
  884.  
  885. : >CURSOR                            \ --- flg 
  886.         TWO_2CHR# 
  887.         PUT_CURS 0 ;
  888.  
  889. : RETMSGZ                            \ --- flg
  890.         RETMSG 0 ;
  891.  
  892. : LENGTH                             \ --- flg
  893.         3BYTE# 1 ;
  894.  
  895. : BELZ                               \ --- flg
  896.         BEL 0 ;
  897.  
  898. : DO_DELAY                           \ --- flg
  899.         DELAY 0 ;
  900.  
  901. PAGE
  902.  
  903. : BOXZ                        \draw box from script entry
  904.         TWO_2CHR#  >R >R 
  905.         TWO_2CHR#  R> R>
  906.         SSWAP
  907.         BOX   0  ;
  908.  
  909. : 1ST_PAGE                      \switch to page #1 --- flg
  910.         0 SET_PAGE# 0 ;
  911.  
  912. : 2ND_PAGE                      \switch to page #2 (CGA only) --- flg
  913.         1 SET_PAGE# 0 ;
  914.  
  915. : TONE_ON                       \ --- flg
  916.         3BYTE# 
  917.         OUTPUT_COUNT @ 
  918.         TONE  ;
  919.  
  920. : TONE_ON_0                     \ --- flg
  921.         TONE_ON 0 ;
  922.  
  923. : TONE_OFF                      \ --- flg
  924.         OFF 0 ;
  925.  
  926. : TONE_BURST                     \ --- flg
  927.         TONE_ON                  \freq, in cps
  928.         200                      \wait for awhile..timer tick
  929.          DO                      \is too slow, so use empty loop
  930.          LOOP                    \AT machines will be higer pitched
  931.         TONE_OFF  ;
  932.  
  933. \clear desired screen area
  934. : CLR_SOME                      \ --- flg
  935.         FOUR.NUMBERS 
  936.         CLR 0 ;
  937.  
  938. : TXT_END                       \script says this is end
  939.         PROGRAMMED_END 
  940.         SET_EXIT 0 ;
  941.  
  942. PAGE
  943.  
  944. : SCRIPT_ACTION         \perform proper action according to script 
  945.                         \file character.    ---
  946.         CASE
  947.         'a' NORMZ               \normal output
  948.         'b' REVERSEZ            \reverse video
  949.         'c' BLINKZ              \blink video
  950.         'd' INTENSZ             \hi intensity video
  951.           \
  952.         'e' RESET_DELAY         \no inter char delay
  953.          \                      
  954.         'f' SDELAY1             \shortest delay
  955.         'g' SDELAY2             \longer delay
  956.         'h' SDELAY3             \yet longer delay
  957.         'i' SDELAY4             \longest delay
  958.           \
  959.         'j' CLSZ                \clear screen & home
  960.         'k' >CURSOR             \move cursor
  961.         'l' RETMSGZ             \halt and wait for prompted input
  962.         'm' LENGTH              \output a string of char
  963.         'n' BELZ                \make a bel
  964.         'o' DO_DELAY            \execute programmed delay
  965.         'p' BOXZ                \draw a box
  966.         'q' 1ST_PAGE            \switch to disp. page#1
  967.         'r' 2ND_PAGE            \switch to disp. page#2
  968.         's' TONE_ON_0           \make programmed tone
  969.         't' TONE_OFF            \turn tone off
  970.         'u' TONE_BURST          \tone on/off
  971.         'v' CLR_SOME            \clr desired part of screen
  972.         'X' TXT_END             \this is the end of script cmmd.
  973.           \
  974.         NOCASE     $$FALSE   
  975.         ENDCASE    EXECUTE ;
  976. PAGE
  977.  
  978. : ?TXT_LEN              \n1 n2 n3 --- n1 n2 n3 n1
  979.         3 PICK ;
  980.  
  981. : SMALLEST_LEN         \ --- n1
  982.         OUTPUT_COUNT @
  983.         ?TXT_LEN  MIN ;
  984.  
  985. \sinfo(txt) sinfo(scrpt) flg --- sinfo(txt) sinfo(scrpt)
  986. : OUTPUT_TEXT 
  987.       IF                                \output text if flg is 1
  988.         SSWAP                           \exchange sinfos
  989.         OVER                            \get addr..sinfo underneath
  990.         SMALLEST_LEN                    \select smallest len
  991.         >R I                            \save in ret. stk
  992.         CPRINTS                         \output sinfo text
  993.         I -                             \
  994.         I +2ND                          \
  995.         SSWAP                           \exchange sinfos
  996.         OUTPUT_COUNT @                  \see if len is different
  997.         R>                              \
  998.         DDUP >                          \
  999.        IF -                            \if so set count = 0
  1000.        ELSE DDROP 0 
  1001.        THEN OUTPUT_COUNT ! 
  1002.       THEN  ;
  1003.  
  1004. : ?NEW_TXT                              \refresh txt buf?
  1005.         DROP3RD/4TH
  1006.         READ_TEXT_FILE 
  1007.         ?TXT_LEN
  1008.         OUTPUT_COUNT @ >
  1009.         IF
  1010.            OUTPUT_COUNT @ 
  1011.            OUTPUT_TEXT 
  1012.            SSWAP 
  1013.            ?TXT_LEN                     
  1014.             0=
  1015.            ?USER_KEY
  1016.         ELSE  
  1017.            NO_TEXT_MSG  1  
  1018.         THEN ;
  1019.  
  1020. : ?TXT_DONE                           \ --- flg
  1021.           ?TXT_LEN                    \remaining text len
  1022.         -IF                           \test if len = 0
  1023. brk1:                                 \label for FDT86 debugger 
  1024.           ?NEW_TXT                    \refresh text buf?
  1025.         ELSE  0                       \else nothing
  1026.         THEN ;
  1027.  
  1028. PAGE
  1029.  
  1030. : PROCESS_TXT_INTERVAL               \sinfo(txt) sinfo(scrpt) ---
  1031.         CGET                         \get script char
  1032.         SCRIPT_ACTION                \perform the script action
  1033.         OUTPUT_TEXT  ;               \output text according 
  1034.                                      \to script control
  1035.  
  1036. : SCRIPT_DONE                        \ ---
  1037.         "Script exhausted" 
  1038.         FPRINTS+CRS 
  1039.         SET_EXIT ;
  1040.  
  1041. : EXECUTE_ONE_SCRIPT            \get a script & execute it
  1042.         SLEN 
  1043.       IF
  1044.         PROCESS_TXT_INTERVAL
  1045.       ELSE SCRIPT_DONE
  1046.       THEN ;
  1047.  
  1048. : ?END_PROCESS
  1049.         ?TXT_DONE                 \text file exhausted?
  1050.         EXIT_FLG @                \user or other exit?
  1051.         FOR  ;                    \either condition?
  1052.  
  1053. : PROCESS_ALL_TXT                 \sinfo(txt) sinfo(scrpt) ---
  1054.         BEGIN
  1055.            EXECUTE_ONE_SCRIPT     \output one text segment
  1056.            ?END_PROCESS           \is there more?
  1057.         UNTIL 
  1058.         SDROP SDROP ;             \throw away all sinfo
  1059.  
  1060. EQUIPMENT  DW   0:410H            \DOS equipment addr
  1061.  
  1062. : SET_CGA/MONO                    \ensure correct crt mode; ---
  1063.         EQUIPMENT @ 
  1064.         30H FAND 
  1065.         30H = 
  1066.      IF 80x25_MONO  
  1067.      ELSE 80x25_BW  
  1068.      THEN 
  1069.         SET_VIDEO_MODE ;
  1070.  
  1071. : INIT                  \intialize variables, screen etc..
  1072.         INIT_TIMER      \save int vector addresses
  1073.         SET_CGA/MONO    \make sure screen is compatible
  1074.         1ST_PAGE DROP   \make sure first display page
  1075.         EXIT_FLG 0! ;   \clear exit flag
  1076.         
  1077.  
  1078. PAGE
  1079.  
  1080. \DOS level command to run this application is:
  1081. \DRIVER DEMO.TXT  SCRIPT.SCR<cr>
  1082. \Batfile command is: RUNDEMO
  1083. \MAIN is entry point and top application word
  1084.  
  1085. : MAIN                          \type demo.txt under control
  1086.                                 \of the script file
  1087.         INIT                    \reset exit
  1088.         OPEN_FILES              \open text & script files
  1089.         READ_FILES
  1090.         PROCESS_ALL_TXT         \output formatted text 'til
  1091.         CLOSE_FILES             \exhausted..back to DOS..
  1092.         SCALE_UP/DOWN    ;      \wind up w/ the scales
  1093.  
  1094. \This is the application end. We hope you can see how
  1095. \powerful and easy FUTURE86 can make your projects...
  1096.  
  1097. END     MAIN
  1098.  
  1099.